package com.jiangli.controller.user;

import com.jiangli.annotation.RateLimit;
import com.jiangli.dto.CollectDishDTO;
import com.jiangli.dto.addCollectDishDTO;
import com.jiangli.result.Result;
import com.jiangli.service.CollectService;
import com.jiangli.vo.CollectDishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/collect")
@Slf4j
@Api(tags = "用户收藏端")
public class CollectController {
    @Autowired
    private CollectService collectService;
    @RateLimit
    @PostMapping("/add")
    public Result addCollectDish(@RequestBody addCollectDishDTO collectDishDTO) {
        log.info("添加菜品{}", collectDishDTO);
        collectService.addDish(collectDishDTO);
        return Result.success();
    }
    @RateLimit
    @GetMapping("/exit")
    @ApiOperation("判断用户是否存在该收藏")
    public Result isExit(@RequestParam Long userId,@RequestParam Long dishId) {
       boolean is= collectService.exit(userId,dishId);
       return Result.success(is);
    }
    @RateLimit
    @GetMapping("/show")
    @ApiOperation("获取用户收藏菜品")
    public Result<CollectDishVO> showUserCollectDish() {
        log.info("用户收藏");
        CollectDishVO collectDishVO = collectService.showUserCollectDish();
        return Result.success(collectDishVO);
    }
    @RateLimit
    @DeleteMapping("/delete")
    @ApiOperation("用户删除收藏菜品")
    public Result deleteCollectDish(@RequestBody CollectDishDTO collectDishDTO) {
        log.info("用户删除菜品{}", collectDishDTO);
        collectService.delete(collectDishDTO);
        return Result.success();
    }
}
